﻿/********************/
/*  By Left Studio  */
/*     @Ho 229      */
/********************/

#include "my_file.h"

#include <QTextStream>
#include <QDataStream>
#include <QDebug>

my_File::my_File(const QString& fileName ,QObject *parent) :
    QObject(parent)
{
    m_File.setFileName(fileName);
    m_FileInfo.setFile(m_File);
}

bool my_File::readFile(QString &Text)
{
	if ((!m_File.open(QFile::ReadOnly | QFile::Text)) || (!m_File.isReadable()))
		return false;

	QDataStream in(&m_File);
	//Text = in.readAll();

	in >> Text;
	qDebug() << "Text = " << Text;
	m_File.close();

	return true;


#if 0
    if((!m_File.open(QFile::ReadOnly | QFile::Text)) || (!m_File.isReadable()))
        return false;

    QTextStream in(&m_File);
    Text=in.readAll();

    m_File.close();

    return true;
#endif
}

bool my_File::writeFile(const QString &Text)
{
	if ((!m_File.open(QFile::WriteOnly | QFile::Text)) || (!m_File.isWritable()))
		return false;

	QDataStream out(&m_File);
	out << Text;

	m_File.close();
	return true;
#if 0
    if((!m_File.open(QFile::WriteOnly | QFile::Text)) || (!m_File.isWritable()))
        return false;

    QTextStream out(&m_File);
    out<<Text;

    m_File.close();
    return true;
#endif
}

/*void my_File::setFileName(const QString &fileName)
{
    m_File.setFileName(fileName);
    m_FileInfo.setFile(m_File);
    m_FileWatcher->addPath(fileName);
}*/
